Overview of Navigation in JavaScript

JavaScript provides a variety of properties and methods to support user navigation. Navigation uses links, anchors and histories, permitting the user to move between information spaces on the World Wide Web.

Recovering navigation information from URLS
hash Specifies the anchor name beginning with a hashmark, #, in a URL, e.g., location.hash. The hash for http://www.myprovider.com:80/~myaccount/foo.html#anchor is #anchor.
host Specifies a portion of the URL including the hostname and port, e.g., location.host. The host for http://www.myprovider.com:80/~myaccount/foo.html#anchor is www.myprovider.com:80.
hostname Specifies the hostname in a URL, e.g., location.hostname. The host for http://www.myprovider.com:80/~myaccount/foo.html#anchor is www.myprovider.com.
href Specifies the entire URL, e.g., location.href. The href for http://www.myprovider.com:80/~myaccount/foo.html#anchor is http://www.myprovider.com:80/~myaccount/foo.html#anchor.
pathname Specifies the path and file name from the URL, e.g., location.pathname. The pathname for http://www.myprovider.com:80/~myaccount/foo.html#anchor is /~myaccount/foo.html.
port Specifies the URL's port, e.g., location.port. The port for http://www.myprovider.com:80/~myaccount/foo.html#anchor is 80.
protocol Specifies the URL's protocol--the start of the URL up to the first colon, e.g., location.protocol. The protocol for http://www.myprovider.com:80/~myaccount/foo.html#anchor is http. Other protocols include ftp, file, news, and gopher.
search Specifies the search string associated with the URL, e.g., location.search. The search for http://www.myprovider.com:80/~myaccount/foo.html?sstring is sstring.
Navigation history
go(anOffset) or go(aString) Loads an old URL from the history list based either on an offset (-3 means three documents ago) or a partial string ("foo" means load the most recent document that contains the string "foo" such as "http://www.myprovider.com/food-list/"), e.g., history.go(-1) moves one document back in the history list. history.go(0) reloads the current document. history.go("xyz") reloads the most recent document whose href contains the substring "xyz".
back() Loads the previous document from the history list, e.g., history.back().
forward() Loads the next document from the history list, e.g., history.forward().
Navigation destination
target Specifies the window or frame name that will host a linked document, e.g., mylink.target.
Navigation events
onMouseOver Triggered when a mouse moves over a link or anchor.
onClick Triggered when a mouse clicks on a link or anchor.
Copyright ©2000 by Charles River Media, All Rights Reserved